package liheng.vue.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import liheng.vue.entity.Emp;
import liheng.vue.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "员工管理",description = "员工服务相关的API接口")
@RestController
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpService empService;

    @Operation(summary = "查询员工信息",description = "查询员工信息")
    @Parameters({
            @Parameter(name = "pageNo",description = "第几页"),
            @Parameter(name = "pageSize",description = "一页最多显示多少条数据"),
            @Parameter(name = "emp",description = "查询条件（姓名，工资）")
    })
    @GetMapping("/find")
    public Map<String,Object> find(@RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                                   @RequestParam(value = "pageSize",defaultValue = "2") Integer pageSize,
                                   Emp emp){
        System.out.println("EmpController.find");

        PageInfo<Emp> pageInfo=empService.find(pageNo,pageSize,emp);


        Map<String,Object> data=new HashMap<>();
        data.put("total",pageInfo.getTotal());
        data.put("emps",pageInfo.getList());



        
        return data;


    }

    @Operation(summary = "添加员工",description = "添加员工")
    @PostMapping("/add")
    public String add(Emp emp){
        System.out.println("EmpController.add");

        empService.add(emp);

        return "success";
    }

    @Operation(summary = "删除员工",description = "删除员工")
    @Parameter(name = "id",description = "编号")
    @GetMapping("/remove")
    public String remove(Integer id){
        System.out.println("EmpController.remove");

        empService.remove(id);

        return "success";
    }

    @Operation(summary = "根据id修改员工状态",description = "删除员工")
    @Parameters({
            @Parameter(name = "id",description = "编号"),
            @Parameter(name = "status",description = "状态")
    })
    @GetMapping("/modifyStatus")
    public String modifyStatus(Integer id,String status){
        empService.modifyStatus(id,status);
        return "success";
    }

    @Operation(summary = "修改员工",description = "删除员工")
    @PostMapping("/modify")
    public String modify(Emp emp){
        empService.modify(emp);
        return "success";
    }
}
